package xx.caffine.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.web.bind.annotation.*;
import xx.caffine.entity.User;
import xx.caffine.service.UserService;

import javax.annotation.Resource;

/**
 * (User)表控制层
 *
 * @author halo-king
 * @since 2023-07-03 16:47:27
 */
@RestController
@RequestMapping("user")
public class UserController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */

    @GetMapping("queryGetById")
    public R queryGetById(Integer id) {
        return success(this.userService.queryGetById(id));
    }

    /**
     * 新增数据
     *
     * @param user 实体对象
     * @return 新增结果
     */

    @PostMapping("insert")
    public R insert(@RequestBody User user) {
        return success(this.userService.insert(user));
    }

    /**
     * 修改数据
     *
     * @param user 实体对象
     * @return 修改结果
     */

    @PostMapping("update")
    public R update(@RequestBody User user) {
        return success(this.userService.update(user));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */

    @PostMapping("delete")
    public R delete(@RequestParam Integer id) {
        return success(this.userService.delete(id));
    }
}
